package com.taptech.doufu.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.taptech.doufu.R;
import com.taptech.doufu.constant.Constant;
import com.taptech.doufu.listener.HttpResponseListener;
import com.taptech.doufu.services.NovelCreateServices;
import com.taptech.doufu.ui.activity.base.DiaobaoBaseActivity;
import com.taptech.doufu.util.DiaobaoUtil;
import com.taptech.doufu.util.UIUtil;
import com.taptech.doufu.net.httputils.HttpResponseObject;

public class NovelModifiedRecommendDesActivity extends DiaobaoBaseActivity implements HttpResponseListener{
	private EditText edDes;
	private String novelDes,novelId,mDes;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		addShadeBg();
		setContentView(R.layout.activity_novel_modified_recommend_des);
		edDes=(EditText)findViewById(R.id.activity_novel_modified_des_ed);
		novelDes=getIntent().getExtras().getString(Constant.DESC);
		novelId=getIntent().getExtras().getString(Constant.ARTICLE_ID);
		if (novelDes!=null) {
			edDes.setText(novelDes);
		}
	}
	public void back(View v){
		finish();
	}
	public void sure(View v){
		mDes=edDes.getText().toString().trim();
		if (isNullContent(mDes)) {
			UIUtil.toastMessage(this, "介绍语不能为空");
			return;
		}
		NovelCreateServices.getInstance().saveNovelRecommendDesc(this, novelId, mDes);
	}
	private boolean isNullContent(String content){
		return content==null||"".equals(content);
	}
	@Override
	public void handleResponse(int handleType, HttpResponseObject response) {
		// TODO Auto-generated method stub
		if (response.getStatus()==0&&response.getFail_code()==0) {
			UIUtil.toastMessage(this, "修改成功");
			setResult(NovelCreateSetActivity.NOVEL_RECOMMEND_DES_RESULT, getIntent().putExtra(Constant.DESC, mDes));
			finish();
		}else{
			UIUtil.toastMessage(this, DiaobaoUtil.getErrorTips(response));
		}
	}
}
